<template>
	<view class="home">
		<titleName :name="name" :backShow="false" />
		<view class="title-content" v-if="isLogin">
			<template v-if="!controller">
				<view class="enterprise">企业名称：{{enterpriseDetail?.customername}} </view>
				<view class="administration">行政归属：{{district}}</view>
				<view class="admin-one">环保管理员1：{{enterpriseDetail?.hbperson}}</view>
				<view class="admin-two">环保管理员2：{{enterpriseDetail?.hbpersonsecond}}</view>
			</template><template v-if="controller">
				<view class="enterprise">单位：{{enterpriseDetail.parentdepartmentname || '无'}} </view>

				<view class="admin-one">姓名：{{enterpriseDetail.username}}</view>

			</template>
		</view>
		<view class="title-content login-btn" v-if="!isLogin">
			<button @click="goLogin">立即登录</button>
		</view>
		<!-- 登录成功 -->
	
		<!-- <view class="main-content-login" v-if="isLogin && operationUnit"> -->
		<view class="main-content-login" v-if="isLogin && !operationUnit">
			<view class="enterprise-msg" @click="jumpEnterprise">
				<image src="https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/qiyexinxi.png"
					mode=""></image>
				<view class="text">{{controller?'企业管理':'企业信息'}}</view>
			</view>
			<view class="facility" @click="jumpFacility">
				<image :src="controller?'../../static/fankui-new.png':'../../static/qiyesheshi.png'" mode="">
				</image>
				<view class="text">{{controller?'反馈管理':'防治设施'}}</view>
			</view>
			<view class="rubbish-change" @click="jumpRubbishChange">
				<image src="../../static/haocaigenghuan.png" mode=""></image>
				<view class="text">{{controller?'更换记录':'耗材替换'}}</view>
			</view>
			<view class="rubbish-change" @click="jumpWastedisposal">
				<image src="https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/weifeiyunshu.png"
					mode=""></image>
				<view class="text">{{controller?'处置记录':'涉废管理'}}</view>
			</view>
			<view class="rubbish-change" @click="jumpWarningControl">
				<image src="https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/yujing.png" mode="">
				</image>
				<view class="text">预警管控</view>
			</view>
			<view class="rubbish-change" v-if="controller" @click="jumpAdminCom">
				<image src="../../static/fankuiguanli.png" mode="">
				</image>
				<view class="text">行政代办</view>
			</view>
			<view class="rubbish-change" @click="jumpStatistics" v-if="controller">
				<image src="../../static/tongji.png" mode=""></image>
				<view class="text">统计</view>
			</view>
			<view class="rubbish-change">
				<image src="../../static/qita.png" mode=""></image>
				<view class="text">其他</view>
			</view>
		</view>
		<!-- 处置单位 -->
		<view class="main-content-login" v-if="operationUnit">
			<view class="enterprise-msg" @click="jumpOperationEnterpriseMsg">
				<image src="https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/qiyexinxi.png"
					mode=""></image>
				<view class="text">企业信息</view>
			</view>
			<view class="facility" @click="jumpTransferManage">
				<image src="../../static/zhuanyi.png" mode="">
				</image>
				<view class="text">转移管理</view>
			</view>
			<view class="rubbish-change" @click="jumpWarningControl">
				<image src="https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/yujing.png" mode="">
				</image>
				<view class="text">预警管控</view>
			</view>
			<view class="rubbish-change">
				<image src="../../static/qita.png" mode=""></image>
				<view class="text">其他</view>
			</view>
		</view>
		<!-- 登录成功后的免费咨询 -->
		<view class="login-search" v-if="isLogin">
			<view class="enterprise-msg" @click="jumpEnvironmentalprotection">
				<image src="https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/xinwenzixun.png"
					mode=""></image>
				<view class="text">环保资讯</view>
			</view>
			<view class="facility" @click="jumpThirdparty">
				<image src="https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/disanfang.png"
					mode=""></image>
				<view class="text">第三方检测</view>
			</view>
			<view class="rubbish-change" @click="jumpPollutionAbat">
				<image src="https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/wuranzhili.png"
					mode=""></image>
				<view class="text">污染治理</view>
			</view>
			<view class="rubbish-change" @click="jumpConsultation">
				<image src="https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/zixun.png" mode="">
				</image>
				<view class="text">环评咨询</view>
			</view>


		</view>
		<view class="main-content" v-if="!isLogin">

			<view class="enterprise-msg" @click="jumpEnvironmentalprotection">
				<image src="https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/xinwenzixun.png"
					mode=""></image>
				<view class="text">环保资讯</view>
			</view>
			<view class="rubbish-change" @click="jumpThirdparty">
				<image src="https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/disanfang.png"
					mode=""></image>
				<view class="text">第三方检测</view>
			</view>


			<view class="rubbish-change" @click="jumpPollutionAbat">
				<image src="https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/wuranzhili.png"
					mode=""></image>
				<view class="text">污染治理</view>
			</view>
			<view class="facility" @click="jumpConsultation">
				<image src="https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/zixun.png" mode="">
				</image>
				<view class="text">环评咨询</view>
			</view>

		</view>
	</view>
</template>

<script setup>
	import titleName from '../../components/titleName.vue';
	import {
		onShow
	} from '@dcloudio/uni-app'
	import http from '../../request/index'
	import {
		reactive,
		ref
	} from 'vue'
	let name = ref('首页')
	let controller = ref(false)
	let isLogin = ref(true)
	let operationUnit = ref(false)
	let enterpriseDetail = ref({
		hbperson: ''
	})
	let district = ref('')
	let findId = function(data) {

		let id = enterpriseDetail?.value?.district

		let res = data.map((item) => {
			if (item.id == id) {

				district.value = item.regionname
				return
			}
			if (item.lstSubNodes && item.lstSubNodes.length > 0) {
				return findId(item.lstSubNodes)
			}
		})

	}

	onShow(() => {
		if (uni.getStorageSync('TOKEN')) {
			isLogin.value = true
		} else {
			isLogin.value = false
			return
		}
		operationUnit.value = uni.getStorageSync('operationUnit')
		// console.log(operationUnit.value, 'operationUnit')
		controller.value = uni.getStorageSync("admin")
		if (controller.value) {
			http({
				url: '/user/selfinfo',
				// method: 'patch'
			}).then((res) => {
				console.log(res, 'res');
				enterpriseDetail.value = res.data
			})
		} else {
			http({
				url: '/enterprise/detail'
			}).then((res) => {
				console.log(res, 'res');
				if (res.code == 0) {
					if (res.data) {
						enterpriseDetail.value = res.data
						res.data.hbperson && uni.setStorageSync('hbperson', res.data.hbperson)
						uni.setStorageSync('hbmobile', res.data.hbmobile)
						uni.setStorageSync('hbpersonsecond', res.data.hbpersonsecond)
						uni.setStorageSync('hbmobilesecond', res.data.hbmobilesecond)
						uni.setStorageSync('customername1', res.data.customername)

					}

				}

			})
		}



		http({
			url: '/region/datalisttree'
		}).then((res) => {
			let data = res.data
			findId(data)

		})
	})

	//产废单位
	let jumpOperationEnterpriseMsg = () => {
		uni.navigateTo({
			url: "/operationUnitPageOhter/enterprise-msg/enterprise-msg"
		})
	}
	let jumpTransferManage = () => {
		uni.navigateTo({
			url: "/operationUnitPageOhter/transfermanage/transfermanage"
		})
	}
	/* -- */
	let jumpAdminCom = () => {
		uni.navigateTo({
			url: "/contorllerPageOther/admincommission/admincommission"
		})
	}
	let jumpConsultation = () => {
		uni.navigateTo({
			url: "/homePageOther/consultation/consultation"
		})
	}
	let jumpEnvironmentalprotection = () => {
		uni.navigateTo({
			url: "/homePageOther/environmentalprotection/environmentalprotection"
		})
	}
	let jumpSupervision = () => {
		uni.navigateTo({
			url: "/homePageOther/supervision-information/supervision-information"
		})
	}
	let jumpEnterprise = () => {
		if (controller.value) {
			uni.navigateTo({
				url: "/contorllerPageOther/enterprisemanage/enterprisemanage?agent=0"
			})
		} else {
			uni.navigateTo({
				url: "/homePageOther/enterprise-msg/enterprise-msg"
			})
		}

	}
	let jumpStatistics = () => {
		if (controller.value) {
			uni.navigateTo({
				url: "/contorllerPageOther/statistics/statistics"
			})
		}
	}
	let jumpFacility = () => {
		if (controller.value) {
			uni.navigateTo({
				url: "/contorllerPageOther/feedback/feedback"
			})
		} else {
			uni.navigateTo({
				url: "/homePageOther/facility/facility"
			})
		}

	}
	let jumpThirdparty = () => {
		uni.navigateTo({
			url: "/homePageOther/thirdpartydetection/thirdpartydetection"
		})
	}
	let jumpRubbishChange = () => {
		if (controller.value) {
			uni.navigateTo({
				url: "/contorllerPageOther/changeRecord/changeRecord?type=1"
			})
		} else {
			uni.navigateTo({
				url: "/homePageOther/rubbishChange/rubbishChange"
			})
		}

	}
	let jumpHazardousWaste = () => {
		uni.navigateTo({
			url: "/homePageOther/wastedisposal/wastedisposal"
		})
	}
	let jumpWastedisposal = () => {
		if (controller.value) {
			uni.navigateTo({
				url: "/contorllerPageOther/changeRecord/changeRecord?type=2"
			})
		} else {
			uni.navigateTo({
				url: "/homePageOther/wastedisposal/wastedisposal"
			})
		}

	}
	let goLogin = () => {
		uni.navigateTo({
			url: "/pages/login/login"
		})
	}
	let jumpPollutionAbat = () => {
		uni.navigateTo({
			url: "/homePageOther/pollutionabatement/pollutionabatement"
		})
	}
	let jumpWarningControl = () => {
		if (controller.value) {
			uni.navigateTo({
				url: "/contorllerPageOther/warningcontrol/warningcontrol"
			})
		} else {
			uni.navigateTo({
				url: "/homePageOther/warningcontrol/warningcontrol"
			})
		}
	}
</script>

<style lang="scss" scoped>
	.home {
		width: 100vw;
		min-height: 100vh;
		background: url("https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/hone-img.png") no-repeat;
		background-size: 100% 100%;
		box-sizing: border-box;
		padding-top: 160rpx;


		.title-content {
			margin-left: 81rpx;
			font-weight: 500;
			font-size: 29rpx;
			color: #FFFFFF;
			line-height: 48rpx;
			margin-bottom: 42rpx;
			position: sticky;
			top: 160rpx;
		}

		.login-btn {
			margin-top: 46rpx;
			margin-bottom: 90rpx;

			button {
				width: 298rpx;
				height: 73rpx;
				border-radius: 36rpx;
				border: 1px solid #FFFFFF;

				font-weight: 500;
				font-size: 29rpx;
				color: #FFFFFF;

			}
		}

		.login-search {
			width: 750rpx;
			height: 704rpx;
			background: #ECECEE;
			border-top-left-radius: 35rpx;
			border-top-right-radius: 35rpx;
			display: flex;
			flex-wrap: wrap;
			padding: 43rpx 0 43rpx 36rpx;

			position: absolute;
			z-index: 9999;



			view:nth-of-type(2n+2) {
				margin-left: 28rpx;

			}

			.rubbish-change {
				margin-top: 23rpx;
			}

			.enterprise-msg,
			.facility,
			.rubbish-change {
				width: 324rpx;
				height: 303rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 0rpx 76rpx 0rpx #EDF2FF;
				border-radius: 21rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				flex-direction: column;

				image {
					width: 104rpx;
					height: 104rpx;
					background: linear-gradient(-20deg, #FC4B3A, #FC7E2D);
					border-radius: 28rpx;
				}

				.text {

					font-weight: 500;
					font-size: 28rpx;
					color: #000000;
					margin-top: 48rpx !important;

				}
			}
		}

		.main-content-login {
			display: flex;
			flex-wrap: wrap;
			padding: 34rpx 36rpx 40rpx 36rpx;
			width: 750rpx;

			background: #FAFCFF;
			position: relative;
			z-index: 99;
			border-top-right-radius: 35rpx;
			border-top-left-radius: 35rpx;

			view:nth-of-type(1),
			view:nth-of-type(2) {
				margin-top: 0rpx !important;
			}

			view:nth-of-type(2n+3) {
				margin-left: 0;
			}

			.rubbish-change,
			.facility,
			.enterprise-msg:nth-of-type(2n+2) {
				margin-left: 28rpx;
				margin-top: 22rpx;
			}

			.rubbish-change,
			.facility,
			.enterprise-msg {
				width: 324rpx;
				height: 303rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 0rpx 76rpx 0rpx #EDF2FF;
				border-radius: 21rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;

				image {
					width: 104rpx;
					height: 104rpx;
					// background: linear-gradient(-27deg, #0871F5, #52BCFD);
					border-radius: 28rpx;
				}

				.text {
					margin-top: 47rpx !important;
					font-weight: 500;
					font-size: 28rpx;
					color: #000000;

				}
			}
		}

		.main-content {
			// height: calc(100vh - 373rpx);
			width: 100vw;

			border-top-left-radius: 35rpx;
			border-top-right-radius: 35rpx;
			background: #FFFFFF;
			display: flex;
			flex-wrap: wrap;
			padding: 34rpx 34rpx 211rpx 36rpx;

			view:nth-of-type(2n+2) {
				margin-left: 28rpx;
			}

			view {
				margin-top: 22rpx;
			}

			view:nth-of-type(1),
			view:nth-of-type(2) {
				margin-top: 0rpx;
			}

			.enterprise-msg,
			.facility,
			.rubbish-change,
			.rubbish-dispose,
			.supervision-information,
			.else {
				width: 324rpx;
				height: 303rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 0rpx 76rpx 0rpx #EDF2FF;
				border-radius: 21rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				padding: 61rpx 0 61rpx 0;
				justify-content: space-between;

				image {
					width: 105rpx;
					height: 105rpx;

				}

				.text {

					font-weight: 500;
					font-size: 28rpx;
					color: #000000;

				}
			}
		}
	}
</style>